using System;
using System.Reflection;
using ConeFabric.Troy.Core;
using System.IO;
using NUnit.Framework;
using System.Collections.Generic;

namespace ConeFabric.Troy.Console
{
    public class Console
    {
        public static void Main(String[] args)
        {
            if (args.Length != 1)
            {
                System.Console.Error.WriteLine("Usage: Troy.exe [assembly file]");
                return;
            }

            FileInfo fileInfo = new FileInfo(args[0]);
            if (!fileInfo.Exists)
            {
                System.Console.Error.WriteLine("Can't find the file: {0}", args[0]);
                return;
            }

            Model model = new Model();
            model.Load(fileInfo.FullName);
            StringWriter writer = new StringWriter();
            writer.WriteLine("Assembly: {0}", fileInfo.Name);
            Dictionary<string, string[]> hierarchy = model.GetTypeHierarchy("NUnit.Framework.TestAttribute");
            Exception[] exceptions = model.LoaderExceptions;

            Model.WriteExceptions(exceptions, writer);
            Model.WriteHierarchy(hierarchy, writer);
            System.Console.Write(writer.GetStringBuilder().ToString());
        }
    }
}